//
//  ViewController.m
//  Reader
//
//  Created by 钟纪旺 on 16/12/7.
//  Copyright © 2016年 zjw. All rights reserved.
//

#import "ViewController.h"
#import "YBPopupMenu.h"
#define TITLES @[@"充值", @"阅读历史", @"常见问题",@"联系客服",@"设置"]
#define ICONS  @[@"motify",@"delete",@"saoyisao",@"pay"]
@interface ViewController ()<YBPopupMenuDelegate>
@property (weak, nonatomic) IBOutlet UIScrollView *scrollview;
@property (weak, nonatomic) IBOutlet UIBarButtonItem *addItem;

@end

@implementation ViewController

- (IBAction)onButton:(UIButton *)sender {
    
    _scrollview.contentOffset = CGPointMake(sender.tag *self.view.frame.size.width, 0);
    
}

- (IBAction)onD:(UIButton *)sender {
    
     [YBPopupMenu showRelyOnView:sender titles:TITLES icons:ICONS menuWidth:120 delegate:self];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
     self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"hei"]]];
    
    UIButton *tmpBtn = [UIButton buttonWithType:UIButtonTypeContactAdd];
    tmpBtn.frame = CGRectMake(0, 0, 25, 25);
    tmpBtn.tintColor = [UIColor whiteColor];
    [tmpBtn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
    
    [_addItem setCustomView:tmpBtn];
    
    _scrollview.scrollEnabled = YES;
   [_scrollview setContentSize:CGSizeMake(self.view.frame.size.width*4, self.view.frame.size.height)];
    
    // Do any additional setup after loading the view, typically from a nib.
}
-(void)viewDidAppear:(BOOL)animated

{
    
    _scrollview.contentSize =CGSizeMake([UIScreen mainScreen].bounds.size.width*4,0);
    _scrollview.pagingEnabled = YES;
    _scrollview.bounces = NO;
    
}
-(void)btnClicked:(UIButton *)sender
{
     [YBPopupMenu showRelyOnView:sender titles:TITLES icons:ICONS menuWidth:120 delegate:self];
}

//- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
//{
//    UITouch *t = touches.anyObject;
//    CGPoint p = [t locationInView: self.view];
//    
//    YBPopupMenu *popupMenu = [[YBPopupMenu alloc] initWithTitles:TITLES icons:nil menuWidth:110 delegate:nil];
//    popupMenu.dismissOnSelected = NO;
//    popupMenu.isShowShadow = YES;
//    popupMenu.delegate = self;
//    popupMenu.offset = 10;
//    popupMenu.type = YBPopupMenuTypeDark;
//    [popupMenu showAtPoint:p];
//}
#pragma mark - YBPopupMenuDelegate
- (void)ybPopupMenuDidSelectedAtIndex:(NSInteger)index ybPopupMenu:(YBPopupMenu *)ybPopupMenu
{
    NSLog(@"点击了 %@ 选项",TITLES[index]);
}
//下导航消失
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.tabBarController.tabBar.hidden = YES;
}

////下导航出现
//- (void)viewWillDisappear:(BOOL)animated {
//    
//    [super viewWillDisappear:animated];
//    [super viewWillAppear:animated];
//    //    self.navigationController.tabBarController.tabBar.hidden = NO;
//}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}





@end
